package com.zerox.order.controller;

import com.zerox.commons.utils.ResponseResult;
import com.zerox.order.domain.pojo.Payment;
import com.zerox.order.openfeign.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @auth wzy
 * @date 2023/3/15 11:34
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private PaymentFeignService paymentFeignService;

    @PostMapping("/create")
    public ResponseResult create(String serial){
        // 创建订单 省略。。。

        // 调用支付接口，发起一个请求
        Payment payment = new Payment(null, serial);

        ResponseResult responseResult = paymentFeignService.create(payment);

        return responseResult;
    }

    @GetMapping("/{id}")
    public ResponseResult getPayment(@PathVariable Long id){

        ResponseResult responseResult =paymentFeignService.getPayment(id);

        return responseResult;
    }
}
